package com.huawei.appmarket.service.appdetail.view.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import o.azb;
import o.dsa;
import o.epr;
import o.epv;
import o.ewm.c;
import o.ewm.h;
import o.ewm.j;

public class HorizonTabNavigator extends HorizontalScrollView {
    private float ʻ = 0.0f;
    private int ʼ = 0;
    private LayoutParams ʽ;
    private ViewPager ˊ;
    private Drawable ˊॱ;
    private LinearLayout ˋ;
    private dsa[] ˋॱ;
    private final d ˎ = new d();
    private int ˏ;
    private e ˏॱ;
    private int ͺ = 0;
    private LayoutInflater ॱ;
    private int ॱˊ = 0;
    private Rect ॱॱ;
    private int ᐝ = 10;

    class d implements OnPageChangeListener {
        final /* synthetic */ HorizonTabNavigator ॱ;

        private d(HorizonTabNavigator horizonTabNavigator) {
            this.ॱ = horizonTabNavigator;
        }

        public void onPageScrolled(int i, float f, int i2) {
            this.ॱ.ʼ = i;
            this.ॱ.ʻ = f;
            this.ॱ.ˋ(i, (int) (((float) this.ॱ.ˋ.getChildAt(i).getWidth()) * f));
            this.ॱ.invalidate();
        }

        public void onPageScrolled(int i) {
            if (i != 0) {
                return;
            }
            if (this.ॱ.ˊ.getCurrentItem() == 0) {
                this.ॱ.scrollTo(0, 0);
            } else if (this.ॱ.ˊ.getCurrentItem() == this.ॱ.ˏ - 1) {
                this.ॱ.scrollTo(this.ॱ.ˋ(), 0);
            } else {
                this.ॱ.ˋ(this.ॱ.ˊ.getCurrentItem(), 0);
            }
        }

        public void onPageScrollStateChanged(int i) {
            if (this.ॱ.ˏॱ != null) {
                this.ॱ.ˏॱ.ˊ(i);
            }
        }
    }

    public interface e {
        void ˊ(int i);
    }

    public HorizonTabNavigator(Context context) {
        super(context);
        ˊ(context);
    }

    public HorizonTabNavigator(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˊ(context);
    }

    public void setViewPager(ViewPager viewPager) {
        this.ˊ = viewPager;
        if (viewPager.getAdapter() == null) {
            throw new IllegalStateException("ViewPager does not have adapter instance.");
        }
        viewPager.setOnPageChangeListener(this.ˎ);
        ˎ();
    }

    private void ˊ(Context context) {
        int i;
        this.ॱ = LayoutInflater.from(context);
        this.ˋॱ = new dsa[3];
        for (i = 0; i < this.ˋॱ.length; i++) {
            this.ˋॱ[i] = new dsa(getContext());
        }
        this.ॱॱ = new Rect();
        setFillViewport(true);
        setWillNotDraw(false);
        this.ˋ = new LinearLayout(context);
        this.ˋ.setOrientation(0);
        this.ˋ.setGravity(17);
        if (epr.ˎ().ॱॱ()) {
            i = getContext().getResources().getDimensionPixelOffset(o.ewm.d.ˊʻ);
        } else {
            i = getContext().getResources().getDimensionPixelOffset(o.ewm.d.ˊʼ);
        }
        int paddingTop = getPaddingTop();
        if (azb.ˎ(getContext())) {
            i += (azb.ॱ(getContext()) - epv.ˎ(context)) / 2;
            setPadding(i, paddingTop, i, paddingTop);
        } else {
            setPadding(i, paddingTop, i, paddingTop);
        }
        addView(this.ˋ);
        this.ᐝ = (int) TypedValue.applyDimension(1, (float) this.ᐝ, getResources().getDisplayMetrics());
        this.ʽ = new LayoutParams(-1, epv.ˋ(getContext(), 28));
        this.ʽ.weight = 1.0f;
        LayoutParams layoutParams = this.ʽ;
        LayoutParams layoutParams2 = this.ʽ;
        int ˋ = epv.ˋ(getContext(), 4);
        layoutParams2.rightMargin = ˋ;
        layoutParams.leftMargin = ˋ;
        this.ͺ = getResources().getColor(c.ॱˎ);
        this.ˊॱ = getResources().getDrawable(o.ewm.e.ͺ);
    }

    public void ˎ() {
        this.ˋ.removeAllViews();
        this.ˏ = this.ˊ.getAdapter().getCount();
        for (int i = 0; i < this.ˏ; i++) {
            if (this.ˊ.getAdapter().getPageTitle(i) != null) {
                ˋ(i, this.ˊ.getAdapter().getPageTitle(i).toString());
            }
        }
        View textView = new TextView(getContext());
        textView.setVisibility(4);
        textView.setMinWidth(0);
        this.ˋ.addView(textView);
    }

    private void ˋ(final int i, String str) {
        View inflate = this.ॱ.inflate(h.ٴ, this, false);
        TextView textView = (TextView) inflate.findViewById(j.ʹॱ);
        textView.setText(str);
        textView.setTextSize(1, 13.0f);
        textView.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ HorizonTabNavigator ˊ;

            public void onClick(View view) {
                this.ˊ.ˊ.setCurrentItem(i, Math.abs(this.ˊ.ˊ.getCurrentItem() - i) <= 2);
            }
        });
        this.ˋ.addView(inflate, i, this.ʽ);
    }

    private void ˏ(Rect rect) {
        View childAt = this.ˋ.getChildAt(this.ʼ);
        if (childAt != null) {
            float f;
            TextView textView = (TextView) childAt.findViewById(j.ʹॱ);
            float left = (float) (childAt.getLeft() + textView.getLeft());
            float width = ((float) textView.getWidth()) + left;
            if (this.ʻ <= 0.0f || this.ʼ >= this.ˏ - 1) {
                f = width;
                width = left;
            } else {
                View childAt2 = this.ˋ.getChildAt(this.ʼ + 1);
                TextView textView2 = (TextView) childAt2.findViewById(j.ʹॱ);
                float left2 = (float) (childAt2.getLeft() + textView2.getLeft());
                left = (left * (1.0f - this.ʻ)) + (this.ʻ * left2);
                f = ((((float) textView2.getWidth()) + left2) * this.ʻ) + (width * (1.0f - this.ʻ));
                width = left;
            }
            rect.set(((int) width) + getPaddingLeft(), (getPaddingTop() + childAt.getTop()) + textView.getTop(), ((int) f) + getPaddingLeft(), textView.getHeight() + ((childAt.getTop() + getPaddingTop()) + textView.getTop()));
        }
    }

    private int ˋ() {
        if (getChildCount() > 0) {
            return Math.max(0, ((getChildAt(0).getWidth() - getWidth()) + getPaddingLeft()) + getPaddingRight());
        }
        return 0;
    }

    private void ˋ(int i, int i2) {
        if (this.ˏ != 0) {
            ˏ(this.ॱॱ);
            int i3 = this.ॱˊ;
            if (this.ॱॱ.left < getScrollX() + this.ᐝ) {
                i3 = this.ॱॱ.left - this.ᐝ;
            } else if (this.ॱॱ.right > (getScrollX() + getWidth()) - this.ᐝ) {
                i3 = (this.ॱॱ.right - getWidth()) + this.ᐝ;
            }
            if (i3 != this.ॱˊ) {
                this.ॱˊ = i3;
                scrollTo(i3, 0);
            }
        }
    }

    public void draw(Canvas canvas) {
        int height;
        super.draw(canvas);
        ˏ(this.ॱॱ);
        if (this.ˊॱ != null) {
            this.ˊॱ.setBounds(this.ॱॱ);
            this.ˊॱ.draw(canvas);
        }
        int i = 0;
        while (i < this.ˋ.getChildCount()) {
            if (i < this.ʼ - 1 || i > this.ʼ + 1) {
                i++;
            } else {
                View childAt = this.ˋ.getChildAt(i);
                TextView textView = (TextView) childAt.findViewById(j.ʹॱ);
                if (textView != null) {
                    dsa o_dsa = this.ˋॱ[(i - this.ʼ) + 1];
                    int save = canvas.save();
                    ˏ(this.ॱॱ);
                    canvas.clipRect(this.ॱॱ);
                    o_dsa.ˎ(textView.getText());
                    o_dsa.ˋ(0, textView.getTextSize());
                    o_dsa.ˏ(this.ͺ);
                    int left = ((childAt.getLeft() + textView.getLeft()) + ((textView.getWidth() - o_dsa.getIntrinsicWidth()) / 2)) + getPaddingLeft();
                    height = ((((textView.getHeight() - o_dsa.getIntrinsicHeight()) / 2) + (childAt.getTop() + textView.getTop())) + getPaddingTop()) + (o_dsa.ˎ() / 2);
                    o_dsa.setBounds(left, height, o_dsa.getIntrinsicWidth() + left, o_dsa.getIntrinsicHeight() + height);
                    o_dsa.draw(canvas);
                    canvas.restoreToCount(save);
                }
                i++;
            }
        }
        height = canvas.save();
        canvas.translate((float) getScrollX(), 0.0f);
        canvas.restoreToCount(height);
    }

    public void setOnPageSelectListener(e eVar) {
        this.ˏॱ = eVar;
    }
}
